
//
//  HomeTabVCHeaderView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/10/26.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "HomeTabVCHeaderView.h"
#import "SDCycleScrollView.h"
#import "HomeModel.h"
@interface HomeTabVCHeaderView()<SDCycleScrollViewDelegate>
@property(nonatomic,strong) SDCycleScrollView *cycleScrollView;
@property(nonatomic,strong) NSMutableArray *banners;
@end
@implementation HomeTabVCHeaderView
-(NSMutableArray *)banners
{
    if (!_banners) {
         _banners = [NSMutableArray array];

    }
    return _banners;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self reloadInternetData];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(qingqiuHomeBanner:) name:@"qingqiuHomeBanner" object:nil];
    }
    return self;
}
-(void)reloadInternetData
{
    self.banners = nil;
    [self.cycleScrollView removeFromSuperview];
    NSDictionary *dict = @{
                           @"fatherId":@"1"
                           };
    [CustomeManager POSTWithURLIndex:12 parameters:dict success:^(NSDictionary *dict) {
        
    } failure:^(NSError *error) {
        
    }];
}
-(void)qingqiuHomeBanner:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
//    XLog(@"dict:%@",dict);
    [self.banners removeAllObjects];
    NSArray *date = [dict objectForKey:@"date"];
    for (NSDictionary *dict in date) {
        HomeModel *model = [HomeModel mj_objectWithKeyValues:dict];
        [self.banners addObject:model.icon];
//        XLog(@"model.icon:%@",model.icon);
    }
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kUIScreen.size.width, kUIScreen.size.width/750*480) delegate:self placeholderImage:[ImageColorHelper createImageWithColor:[UIColor colorWithRed:174/255.0 green:204/255.0 blue:249/255.0 alpha:1]]];
    self.cycleScrollView.delegate = self;
    self.cycleScrollView.backgroundColor = kBg;
    self.cycleScrollView.autoScroll = YES;
    self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    [self addSubview:self.cycleScrollView];
    self.cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.cycleScrollView.showPageControl = YES;
//    XLog(@"self.banners:%@",self.banners);
    self.cycleScrollView.imageURLStringsGroup = self.banners;
    //http://cdn.duitang.com/uploads/item/201209/05/20120905174148_GSK5r.jpeg
    self.cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"bannerSelected"];
    self.cycleScrollView.pageDotImage = [UIImage imageNamed:@"bannerNormal"];
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
